from u8.u8_helper import MssqlHelper


class Person:
    db = None
    table='Person'

    def __init__(self, db_name='UFDATA_201_2018'):
        self.db = MssqlHelper(db_name)

    def get(self, name):
        sql = f"select cPersonCode, cPersonName, cDepCode from {self.table} where cPersonName like '%{name}%'"
        rows = self.db.query_all(sql)
        for row in rows:
            print(f'业务员编码：{row[0]}, 业务员姓名： {row[1]}，部门： {row[2]}')

    def update_saleBillVouch(self, cPersonCode, cSBVCode):
        sql = f"update SaleBillVouch set cPersonCode='{cPersonCode}' where cSBVCode='{cSBVCode}'"
        self.db.update(sql)
        print(f'发票号：{cSBVCode}, 业务员已更新')

    def update_saleOrder(self, cPersonCode, cSOCode):
        sql = f"update SO_SOMain set cPersonCode='{cPersonCode}' where cSOCode='{cSOCode}'"
        self.db.update(sql)
        print(f'销售订单：{cSOCode}, 业务员已更新')

    def update_dispatchList(self, cPersonCode, cDLCode):
        sql = f"update DispatchList set cPersonCode='{cPersonCode}' where cDLCode='{cDLCode}'"
        self.db.update(sql)
        print(f'发货单：{cDLCode}, 业务员已更新')
